package com.ktg.mes.pda.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.pda.mapper.PdaLabelTypeItemMapper;
import com.ktg.mes.pda.domain.PdaLabelTypeItem;
import com.ktg.mes.pda.service.IPdaLabelTypeItemService;



/**
 * PDA采集标签项Service业务层处理
 *
 * @author byteco
 * @date 2023-03-03
 */
@Service
public class PdaLabelTypeItemServiceImpl extends ServiceImpl<PdaLabelTypeItemMapper, PdaLabelTypeItem> implements IPdaLabelTypeItemService
{




    /**
     * 查询PDA采集标签项
     *
     * @param entity PDA采集标签项
     * @param page 分页对象
     * @return PDA采集标签项
     */
    @Override
    public IPage<PdaLabelTypeItem> queryPageList(PdaLabelTypeItem entity, Page<PdaLabelTypeItem> page) {
        QueryWrapper<PdaLabelTypeItem> lqw = new QueryWrapper<PdaLabelTypeItem>(entity);
        lqw.orderByDesc("create_time");
        IPage<PdaLabelTypeItem> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询PDA采集标签项
     *
     * @param entity PDA采集标签项
     * @return PDA采集标签项
     */
    @Override
    public List<PdaLabelTypeItem> queryList(PdaLabelTypeItem entity) {
        QueryWrapper<PdaLabelTypeItem> lqw = new QueryWrapper<PdaLabelTypeItem>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public PdaLabelTypeItem getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增PDA采集标签项
     *
     * @param entity PDA采集标签项
     * @return 结果
     */
    @Override
    public void insert(PdaLabelTypeItem entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改PDA采集标签项
     *
     * @param entity PDA采集标签项
     * @return 结果
     */
    @Override
    public boolean update(PdaLabelTypeItem entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除PDA采集标签项
     *
     * @param recordIds 需要删除的PDA采集标签项主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] recordIds)
    {

        return this.removeByIds(Arrays.asList(recordIds));
    }

    /**
     * 删除PDA采集标签项信息
     *
     * @param recordId PDA采集标签项主键
     * @return 结果
     */
    @Override
    public boolean delete(Long recordId)
    {
        return this.removeById(recordId);
    }

    private LambdaQueryWrapper<PdaLabelTypeItem> buildQueryWrapper(PdaLabelTypeItem entity) {
        LambdaQueryWrapper<PdaLabelTypeItem> lqw = Wrappers.lambdaQuery();
                    lqw.like(StringUtils.isNotBlank(entity.getName()), PdaLabelTypeItem::getName, entity.getName());
        return lqw;
    }
}
